home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / scripts / linkscheme.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1992-10-23  |  2KB  |  70 lines

  1. #!/bin/sh
  2.  
  3. # This script creates an interpreter that is linked together statically
  4. # with your extensions (on machines that don't support incremental linking).
  5. # The first argument is the executable to be created, the remaining
  6. # arguments are the .o-files of your extensions and optional libraries.
  7. #
  8. # For example, to create an instance of the interpreter containing the X11
  9. # extensions and all the Athena widgets, call in the toplevel directory:
  10. #
  11. #   src/link-scheme xscheme lib/util/*.o lib/xt/*.o lib/xaw/*.o
  12. #                           -lXaw -lXt -lXmu -lXext -lX11 
  13.  
  14. if [ $# = 0 ]
  15. then
  16.     echo Usage: "$0: output-file [object-files]"
  17.     exit 1
  18. fi
  19. ofiles=@ofiles@
  20. aout=$1
  21. if [ -f $aout ]
  22. then
  23.     echo $aout already exists.
  24.     exit 1
  25. fi
  26. shift
  27. extensions=$*
  28.  
  29. # A special case is required for AIX.  The AIX linker discards all object
  30. # files whose external symbols are not referenced.  This stupid `garbage
  31. # collection' cannot be switched off.  Since extensions do not have entry
  32. # points that are called directly, they are garbage collected away by the
  33. # linker (the interpreter scans its symbol table on startup to find the
  34. # entry points and calls them indirectly by using the symbol values).
  35. #
  36. # To avoid this, we have to create an `export list' containing at least one
  37. # external function from each extension.  We are using the init_ functions,
  38. # as it is guaranteed that each extensions exports at least one such function.
  39. #
  40. # We grep in the nm output for all lines of this form (i.e. entries that
  41. # start with .init_ and have a symbol type of "extern"):
  42. # .init_foobar      |    113520|extern|             |      |     |.text
  43. #
  44. # then select the symbol name, and delete the initial period.
  45.  
  46. case @system@ in
  47. *-aix*-*)
  48.     echo Creating export list for stupid AIX linker:
  49.     for e in $extensions
  50.     do
  51.     case $e in
  52.     -l*) ;;
  53.       *)
  54.         nm -e $e | grep '^\.init_.*|extern|' | sed -e 's/[|.]//g' \
  55.         | awk '{print $1}' >> exportlist
  56.         ;;
  57.     esac
  58.     done
  59.     cat exportlist
  60.     @cc@ -o $aout -bexport:exportlist $ofiles $extensions @ldflags@
  61.     rm exportlist
  62.     ;;
  63. *)
  64.     @cc@ -o $aout $ofiles $extensions @ldflags@
  65.     ;;
  66. esac
  67. chmod +x $aout
  68.